/* eslint-disable no-unused-vars */
/**
 * @developer：MR·Feng
 * 封装请求
 */

import HttpAxios from './baseAxios.js';

export default {
    get(url, params, headers) {
        let options = {};
        if (params) options.params = params;
        if (headers) options.headers = headers;
        return HttpAxios.get(url, options);
    },
    post(url, params, headers) {
        let options = {};
        if (headers) options.headers = headers;
        return HttpAxios.post(url, params, options);
    },
    formpost(url, params, headers) {
        let options = {};
        options.headers = headers || {
            'Content-Type': 'multipart/form-data; charset=utf-8;',
        };
        options.transformRequest = [
            (data) => {
                let formData = new FormData();
                for (let key in params) {
                    formData.append(key, params[key]);
                }
                return formData;
            },
        ];
        return HttpAxios.post(url, params, options);
    },
    put(url, params, headers) {
        let options = {};
        if (headers) options.headers = headers;
        return HttpAxios.put(url, params, options);
    },
    delete(url, params) {
        let options = null;
        // if (params) options.params = params;
        // return HttpAxios.delete(url, options);
        if (params) {
            options = url + params.id;
            return HttpAxios.delete(options);
        }
    },
};
